package com.sunlands.zlcx.usercenter.repository;

import com.sunlands.zlcx.usercenter.domain.UsersStudyInfoDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UsersStudyInfoRepository extends JpaRepository<UsersStudyInfoDO, Integer>, JpaSpecificationExecutor<UsersStudyInfoDO> {

    UsersStudyInfoDO findFirstByUserIdOrderByCreateTimeDesc(Long userId);

    @Query(value = "SELECT SUM(study_minutes) FROM tz_user_study_info WHERE user_id in ?1  and create_time >= ?2", nativeQuery = true)
    Integer sumStudyMinute(List<Integer> userIdList, String createTime);
}

